<?php
/**
 * CommonMembersStatus
 *  
 * @author Administrator
 * @version 
 */
class Model_CommonMembersStatus extends Zend_Db_Table_Abstract
{
 
    protected $_name = 'tcl_common_members_status';
    
    //当前用户是否超过刷新值上限
    public function isRefresh($uid) {
    	
        $num = $this->getUserRefreshNum($uid);
		
        
        /* 刷新值可设置 */
		if ($num >= 5) {     	
		 	return false;
		}else{
			$this->setUserRefreshNum($uid);
			return true;
		}

    }
    
    public function getUserRefreshNum($uid) {
    	
        $db = $this->getAdapter();
        $where = $db->quoteInto("uid = ?", $uid)
        		.$db->quoteInto("AND work_day = ?", date('Ymd'));

        $row = $this->fetchAll($where)->count();

        return $row;
    }
    
    /*
    //WORK_DAY 不是当天的 清除 刷新数
    public function setUserRefreshNone($uid) {
        $db = $this->getAdapter();
        
        $set = array(
        	'refresh_num'   => 0,
        	'work_day'		=> date("Ymd"),
        );
        
        $where = $db->quoteInto("uid = ?", $uid);
        
        try {
        	$row = $this->update($set, $where);
        } catch (Exception $e) {
        	echo $e;
        	exit();
        }
        return $row;
    }*/
    
    //刷新数加1
    public function setUserRefreshNum($uid) {

        $data = array(
        	'uid'  =>  $uid,
        	'work_day' => date('Ymd'),
        );

    
    	try {
    		$id = $this->insert($data);
    	} catch (Exception $e) {
    		echo $e;
    		exit();
    	}
    	return $id;
    }
    
    
}
